import { IPanelRawItem } from '@ibiz/model-core'
import { PanelItemController, PanelItemState } from '@ibiz-template/runtime'
import { TeleportPlaceholderState } from './i-biz-teleport-placeholder.state'

/**
 * 传送占位控制器
 *
 * @export
 * @class PanelRawItemController
 * @extends {PanelItemController<IPanelRawItem>}
 */
export class TeleportPlaceholderController extends PanelItemController<IPanelRawItem> {
  declare state: TeleportPlaceholderState

  protected createState(): PanelItemState {
    return new TeleportPlaceholderState(this.parent?.state)
  }

  /**
   * 初始化
   *
   * @author lxm
   * @date 2022-08-24 20:08:42
   * @protected
   * @returns {*}  {Promise<void>}
   */
  protected async onInit(): Promise<void> {
    await super.onInit()
    const viewCodeName = this.panel.view.model.codeName
    let teleportTag = `${viewCodeName?.toLowerCase()}-${this.model.id}`
    const paramTag = this.model.rawItem?.rawItemParams?.find((item) => item.key === 'TeleportTag')
    if (paramTag && paramTag.value) {
      teleportTag = paramTag.value
    }
    ibiz.log.debug(
      ibiz.i18n.t('vue3Util.panelComponent.placeholderIdentifier', {
        viewCodeName,
        id: this.model.id,
      }),
      teleportTag,
    )
    this.state.teleportTag = teleportTag
  }
}
